﻿using System;
using System.Text;
using System.Drawing;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

public static partial class NativeAOT
{
    [UnmanagedCallersOnly(EntryPoint = "gass")]
    public static unsafe double gass_dll(double a, double d, double x)
    {
        return gass(a, d, x);
    }

    /// <summary>
    /// 正态分布函数
    /// </summary>
    /// <param name="a">a数学期望值。</param>
    /// <param name="d">dd*d为方差值。要求d>0。</param>
    /// <param name="x">x随机变量值。</param>
    /// <returns>函数返回正态分布函数值。</returns>
    public static unsafe double gass(double a, double d, double x)
    {
        double y;
        if (d <= 0.0) d = 1.0e-10;
        y = 0.5 + 0.5 * errf((x - a) / (Math.Sqrt(2.0) * d));
        return (y);
    }

    /*
    // 正态分布函数例
      int main()
      { 
          int i,j;
          double a0,d0,x,y;
          double a[2]={ -1.0,3.0};
          double d[2]={ 0.5,15.0};
          for (i=0; i<=1; i++)
          { 
              a0=a[i]; d0=d[i]; x=-10.0;
              for (j=0; j<=4; j++)
              { 
                  y=gass(a0,d0,x);
                  cout <<"P(" <<a0 <<", " <<d0 <<", " <<x <<")=" <<y <<endl;
                  x=x+5.0;
              }
          }
          return 0;
      }
    */
}

